package com.balad.elements;

import java.util.List;

import com.balad.entities.Theme;
import com.balad.services.DataServices;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

import android.graphics.drawable.Drawable;
import android.os.Bundle;

public class ListPoiMapActivity extends MapActivity {

	DataServices dataservices;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listpoimap);
        

        dataservices = (DataServices)getApplicationContext();
        
		int idtheme = getIntent().getIntExtra("themeid", 0);
		
		Theme theme = null ;
		
		for (int i = 0; i < dataservices.getVille().getColThemeSize(); i++) {
			
			if (dataservices.getVille().getTheme(i).getId_theme() == idtheme)
			{
					theme = dataservices.getVille().getTheme(i);			
			}
		}	


        MapView map = (MapView)findViewById(R.id.map);
        MapController mapController = map.getController();
        GeoPoint point = new GeoPoint((int)(dataservices.getVille().getLatitude()*1E6),(int)(dataservices.getVille().getLongitude()*1E6));
        
        Drawable drawable = this.getResources().getDrawable(R.drawable.maps_icon);
        ListItimizedOverlay itemizedoverlay = new ListItimizedOverlay(drawable,this);
         
		for (int i = 0; i < theme.getColPOISize(); i++) {
			
	        GeoPoint geoPoint = new GeoPoint((int)(theme.getPOI(i).getLatitude()*1E6),(int)(theme.getPOI(i).getLongitude()*1E6));
	        OverlayItem overlayitem = new OverlayItem(geoPoint, "POI", theme.getPOI(i).getTitre());
	        itemizedoverlay.addOverlayItem(overlayitem);
			 
		}
			
        
        List<Overlay> mapOverlays = map.getOverlays();
        mapOverlays.add(itemizedoverlay);
        
        
        mapController.setCenter(point);
        mapController.setZoom(16);
        map.invalidate();
    }

    @Override
    protected boolean isRouteDisplayed() { return false; }
}
